<?php
// SomeryC, a webcomic script by Zachary Weston Lewis
// Based on Somery by Robin de Graaf
// Copyright 2005-2007
// SomeryC is distributed under the Artistic License (see LICENSE.txt)
//
// ADMIN/CHAPTERS.PHP > 31-08-2007

$start = TRUE; include("system/include.php"); if ($checkauth) { 
if ($userdata['level'] >= 2) {
if (!$action) { 
   echo "<h1 id='catagories'>Chapters</h1>
      <h2>article chapters</h2>
      <table>"; 
   $result = mysql_query("SELECT * FROM ".$prefix."chapters ORDER BY cid");
   while($row=mysql_fetch_object($result)) { 
      echo "<tr><td>$row->cid - $row->chapter</td><td>";
      if ($row->chapter != "general") {
         echo "<a href='chapters.php?action=edit&cid=$row->cid'>edit</a>";
      } else { 
         echo "cannot be edited"; 
      } 
      echo "</td></tr>"; 
   }
   echo "</table>
      <form method='post' action='chapters.php'>
      <input type='hidden' name='action' value='new'>
      <h2>add a chapter</h2>
      <table>
      <tr><td>chapter name</td><td><input size=50 name='newcat' type='text'></td></tr>
      <tr><td colspan='2'><input type='submit' value='Add Chapter' /></td></tr>
      </table>
      ";
} elseif ($action == "new") { 
   if (!$newcat && !$err) { show_error(13); $err = 1; } 
   if (!$err) { 
   $result = mysql_query("INSERT INTO ".$prefix."chapters (chapter) VALUES ('".$newcat."')");
      echo "<meta http-equiv=Refresh content=0;URL='chapters.php'>";
   } 
} elseif ($action == "edit") { 
   echo "<form method='post' action='chapters.php'>
      <input type='hidden' name='action' value='update'>
      <input type='hidden' name='cid' value='$cid'>
      <h2>edit chapter</h2>
      <table>"; 
   $result = mysql_query("SELECT * FROM ".$prefix."chapters WHERE cid='$cid'");
   while($row=mysql_fetch_object($result)) { 
      echo "<tr><td>chapter name</td><td><input size=50 name='newcat' type='text' value='$row->chapter'></td></tr>";
   } 
   echo " 
   <tr><td>delete this chapter</td><td><input type='checkbox' name='delete'></td></tr>
   <tr><td colspan='2'><input type='submit' value='Save Changes' /></td></tr>
   </table>
   ";
} elseif ($action == "update") { 
   if ($delete) { 
      $result = mysql_query("SELECT * FROM ".$prefix."chapters WHERE chapter = 'general'");
      while($row=mysql_fetch_object($result)) { 
         $setcat = $row->cid; 
      } 
      $result = mysql_query("DELETE FROM ".$prefix."chapters WHERE cid = '$cid'");
      $result = mysql_query("UPDATE ".$prefix."articles SET  
         chapter = '$setcat'
         WHERE chapter = '$cid'");
      echo "<meta http-equiv=Refresh content=0;URL='chapters.php'>";
   } else { 
   if (!$newcat && !$err) { echo $error[13]; $err = 1; } 
   if (!$err) { 
      $result = mysql_query("UPDATE ".$prefix."chapters SET
         chapter='$newcat'
      WHERE cid = '$cid'"); 
         echo "<meta http-equiv=Refresh content=0;URL='chapters.php'>";
   } 
   } 
} 
} 
?> 
<?php }; $start = FALSE; include("system/include.php"); ?>
